package com.lyfei.yd.system.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyfei.yd.common.exception.CustomException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean save(T entity) {
        if (!super.save(entity)) {
            logger.error("保存失败");
            throw new CustomException(entity.getClass().getSimpleName() + "数据保存失败");
        }
        return true;
    }

    @Override
    public boolean updateById(T entity) {
        if (!super.updateById(entity)) {
            logger.error("更新失败");
            throw new CustomException(entity.getClass().getSimpleName() + "数据更新失败");
        }
        return true;
    }
}
